﻿using System;
using IOCDemo.Interfaces;

namespace IOCDemo.Services
{
    public class ConsoleLoggingService : ILoggingService
    {
        #region LogLevels enum

        public enum LogLevels
        {
            Debug,
            Info,
            Error
        }

        #endregion

        public ConsoleLoggingService(ISettingsService settingsService)
        {
            switch (settingsService.GetSetting<string>("LogLevel").ToUpper())
            {
                case "DEBUG":
                    LogLevel = LogLevels.Debug;
                    break;
                case "INFO":
                    LogLevel = LogLevels.Info;
                    break;
                default:
                    LogLevel = LogLevels.Error;
                    break;
            }
        }

        #region Implementation of ILoggingService

        public void Debug(string message)
        {
            if (LogLevel.Equals(LogLevels.Debug))
                Console.WriteLine("DEBUG: " + message);
        }

        public void Info(string message)
        {
            if (LogLevel.Equals(LogLevels.Info))
                Console.WriteLine("INFO: " + message);
        }

        public void Error(string message)
        {
            if (LogLevel.Equals(LogLevels.Error))
                Console.WriteLine("ERROR: " + message);
        }

        #endregion

        public LogLevels LogLevel { get; set; }
    }
}